using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataAccessLayer
{
    public class DAO_Question_Solution
    {
        public static bool Insert(Object tmp)
        {
            QUESTION_SOLUTION obj = (QUESTION_SOLUTION)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            //_list.Add(new SqlParameter("@_TABLE__PK", obj._TABLE__PK));
            //_list.Add(new SqlParameter("@_TABLE__PK2", obj._TABLE__PK2));
            _list.Add(new SqlParameter("@ITEM_ID", obj.ITEM_ID));
            _list.Add(new SqlParameter("@QUESTION_ID", obj.QUESTION_ID));
            //_list.Add(new SqlParameter("@SOLUTION_ID", obj.SOLUTION_ID));
            _list.Add(new SqlParameter("@SOLUTION_ORDER", obj.SOLUTION_ORDER));

            int n = clsDataAccessHelper.ExecNonQuery("sp_question_solution_insert", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static QUESTION_SOLUTION Select(int id)
        {
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@ITEM_ID", id));

            DataTable table = clsDataAccessHelper.ExecuteQuery("sp_question_solution_select", _list);
            if (table != null && table.Rows.Count == 1)
            {
                QUESTION_SOLUTION obj = new QUESTION_SOLUTION();
                obj.ITEM_ID = id;
                obj.QUESTION_ID = decimal.Parse(table.Rows[0]["QUESTION_ID"].ToString());
                obj.SOLUTION_ID = decimal.Parse(table.Rows[0]["SOLUTION_ID"].ToString());
                obj.SOLUTION_ORDER = byte.Parse(table.Rows[0]["SOLUTION_ORDER"].ToString());
                return obj;
            }
            return null;
        }

        public static bool Update(Object tmp)
        {
            QUESTION_SOLUTION obj = (QUESTION_SOLUTION)tmp;
            bool result = false;

            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@_TABLE__PK", obj._TABLE__PK));
            _list.Add(new SqlParameter("@_TABLE__PK2", obj._TABLE__PK2));
            _list.Add(new SqlParameter("@ITEM_ID", obj.ITEM_ID));
            _list.Add(new SqlParameter("@QUESTION_ID", obj.QUESTION_ID));
            _list.Add(new SqlParameter("@SOLUTION_ID", obj.SOLUTION_ID));
            _list.Add(new SqlParameter("@SOLUTION_ORDER", obj.SOLUTION_ORDER));

            int n = clsDataAccessHelper.ExecNonQuery("sp_question_solution_update", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static bool Delete(Object tmp)
        {
            QUESTION_SOLUTION obj = (QUESTION_SOLUTION)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@_TABLE__PK", obj._TABLE__PK));
            _list.Add(new SqlParameter("@_TABLE__PK2", obj._TABLE__PK2));
            _list.Add(new SqlParameter("@ITEM_ID", obj.ITEM_ID));
            _list.Add(new SqlParameter("@QUESTION_ID", obj.QUESTION_ID));
            _list.Add(new SqlParameter("@SOLUTION_ID", obj.SOLUTION_ID));
            _list.Add(new SqlParameter("@SOLUTION_ORDER", obj.SOLUTION_ORDER));

            int n = clsDataAccessHelper.ExecNonQuery("sp_question_solution_delete", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static List<QUESTION_SOLUTION> LoadAll()
        {
            List<QUESTION_SOLUTION> _list = new List<QUESTION_SOLUTION>();
            //call stored getlist here
            return _list;
        }
    }
}
